/**
 * 定义视频存储设置模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.ws.wsclcManager.wsclcInfo.dvrInfomationManager', ['water.entity.dvrInfomation','water.entity.monitorStation']);
	module.controller('DvrInfomationManagerController',function($wdp,$rootScope,$scope,$dvrInfomationService,$monitorStationService){
	/**
	* 新建对话框
	*/
	$scope.createDialog;
	/**
	 * 编辑对话框
	 */
	$scope.editDialog;
	/**
	 * 查询条件
	 */
	$scope.queryObject={};	
	/**
	 * DVR数据
	 */
	$scope.dvrInfomationData={};
	 /**
     * 初始化站点数据
     */
	$scope.stationSelectList=null;
	/**
	 *新建站点数据
	 */
	$scope.stationSelecter;
	/**
	 * 编辑站点数据
	 */
	$scope.stationSelecterEdit;
	/**
	 * 新建数据
	 */
	$scope.dvrInfomationCreate = {};
	/**
	 * 编辑数据
	 */
	$scope.dvrInfomationEdit={};
	/**
	 * 新建按钮点击
	 */
	$scope.onCreateClick=function(){
		$scope.dvrInfomationCreate = {};
		$scope.createDialog.open();
	};
	/**
	 * 新建提交
	 */
	$scope.onSubmitCreateClick = function(data){
		$dvrInfomationService.createModel(data).then(function(){
			$scope._getDvrList();
			$.messager.alert("保存成功","保存成功",'info');
			$scope.createDialog.close();
		});
	};
	/**
	 * 新建取消按钮
	 */
	$scope.onSubmitCancleClick = function(){
			$scope.createDialog.close();
	};
	/**
	 * 编辑按钮点击事件
	 */
	$scope.onEditClick = function(data){
		$scope.dvrInfomationEdit = angular.copy(data);
		$scope.editDialog.open();
	}
	/**
	 * 提交编辑按钮点击事件
	 */
	$scope.onSubmitEditClick = function(data){
		$dvrInfomationService.updateModel(data).then(function(){
			$scope._getDvrList();
			$.messager.alert("保存成功","保存成功",'info');
			$scope.editDialog.close();
		});
	}
	/**
	 * 编辑取消事件
	 */
	$scope.onSubmitEditCancleClick = function(){
		$scope.editDialog.close();
    };
	/**
	 * 删除
	 */
	$scope.onSubmitDeleteClick=function(data){
		$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
			if(r){
				$dvrInfomationService.deleteModel(data.GUID).then(function(){
					$scope._getDvrList();
					$.messager.alert("删除成功","删除成功",'info');
				});			
			}
		});
	}
	/**
	 * 监控污水处理厂id变化
	 */
	if($wdp.viewValue.wwtpDetailParmWatch){
		$wdp.viewValue.wwtpDetailParmWatch();
	};
	$wdp.viewValue.wwtpDetailParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.wwtpDetailParm;},function(){
		if(!$wdp.viewValue.wwtpDetailParm){
			return;
		}
		$scope.queryObject.WWTP_ID = $wdp.viewValue.wwtpDetailParm.WWTPID;
		$scope._getDvrList();
		$scope._getStationSelectList();
    },true);
	/**
	 * 获取DVR数据
	 */
	$scope._getDvrList=function(){
		$dvrInfomationService.getList($scope.queryObject).then(function(d){
			if(d.data.length < 1){
				$scope.dvrInfomationData = {};
				return;
			}
			$scope.dvrInfomationData=d.data;
		});
	};
	/**
	 * 获取站点列表，编辑或者新增的时候需要选择
	 */
	$scope._getStationSelectList = function(){
		$monitorStationService.getDomainList({WWTP_ID:$scope.queryObject.WWTP_ID}).then(function(d){
			$scope.stationSelectList = d;
			$scope.stationSelecter.setData(d);
			$scope.stationSelecterEdit.setData(d);
		});
	};
	
 });
}(window, angular));